package com.sqllog.admin.auth.process;

import com.alibaba.fastjson.JSON;
import com.sqllog.admin.auth.domain.response.Result;
import com.sqllog.admin.framework.tools.ServletUtil;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *  自定义用户注销处理类
 *
 * @author chennengcheng
 * @date 2022-01-14 14:35
 * @remark
 */

@Component
public class SecureLogoutSuccessHandler implements LogoutSuccessHandler {

    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        SecurityContextHolder.clearContext();
        Result result = Result.success("注销成功");
        ServletUtil.write(JSON.toJSONString(result));
    }
}
